<?php
class BuildingPeer extends BaseBuildingPeer
{
public static function GetBuilding()
	{
	$c = new Criteria();
	$c->add(BuildingPeer::STATUS, Constant::RECORD_STATUS_ACTIVE);
	$c->addAscendingOrderByColumn(BuildingPeer::BUILDING_NO);
	$buildings = BuildingPeer::doSelect($c);
	
	return $buildings;
	} // END - GetBuilding

public static function GetVacantBuilding()
	{
	$a = new Criteria();
	$a->add(OccupantPeer::OCCUPIED_STATUS, Constant::BUILDING_OCCUPIED);
	$a->add(OccupantPeer::STATUS, Constant::RECORD_STATUS_ACTIVE);
	$occpants = OccupantPeer::doSelect($a);
	
	$occpants_in_building = array();
	foreach($occpants as $i => $occ)
	{
		$occpants_in_building[$i] = $occ->getBuildingId();
	}
	
	if(!$occpants_in_building)
	{
		$c = new Criteria();
		//$c->add(BuildingPeer::ID, $occpants_in_building, Criteria::NOT_IN);
		$c->add(BuildingPeer::STATUS, Constant::RECORD_STATUS_ACTIVE);
		$c->addAscendingOrderByColumn(BuildingPeer::STATION_ID);
		$c->addAscendingOrderByColumn(BuildingPeer::BUILDING_NO);
		$buildings = BuildingPeer::doSelect($c);
	}
	else 
	{
		$c = new Criteria();
		$c->add(BuildingPeer::STATUS, Constant::RECORD_STATUS_ACTIVE);
		$c->add(BuildingPeer::ID, $occpants_in_building, Criteria::NOT_IN);
		$c->addAscendingOrderByColumn(BuildingPeer::STATION_ID);
		$c->addAscendingOrderByColumn(BuildingPeer::BUILDING_NO);
		$buildings = BuildingPeer::doSelect($c);
	}
	
	if($buildings)
	{
		return $buildings;
	}
	
	else{
		return false;
		}
	} // END - GetVacantBuilding
}
